package com.subject.common.enums;

import lombok.Getter;

@Getter
public enum ResultCodeEnum {
    // 常用状态码
    SUCCESS(200, "成功"),
    BadRequest(400, "请求的语法错误"),
    FAIL(500, "服务器内部错误"),
    // 不常用状态码
    UNAUTHORIZED(401, "没有登录"),
    NOT_FOUND(404, "请求的资源不存在"),
    METHOD_NOT_ALLOWED(405, "请求方法错误"),
    BAD_GATEWAY(502, "网关错误"),
    SERVICE_UNAVAILABLE(503, "服务不可用"),
    GATEWAY_TIMEOUT(504, "网关超时");

    private int code;
    private String msg;
    ResultCodeEnum(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static ResultCodeEnum getResultCodeEnum(int code) {
        for (ResultCodeEnum resultCodeEnum : ResultCodeEnum.values()) {
            if (resultCodeEnum.getCode() == code) {
                return resultCodeEnum;
            }
        }
        return null;
    }
}
